package org.easiermock;

import org.junit.Assert;
import org.junit.Test;


public abstract class AbstractEasierMockTest {
	
	@Test
	public void testInterfaceStub() {
		testStubBehaviour(TestInterface.class, new ExtendsStub());
	}

	@Test
	public void testConcreteSubclassStub() {
		testStubBehaviour(TestObject.class, new ExtendsStub());
	}

	@Test
	public void testConcreteStub() {
		testStubBehaviour(TestObject.class, new NotImplementerStub());
	}

	protected abstract <T extends TestInterface> void testStubBehaviour(Class<T> classToStub, Stub stub);
	
	public static interface TestInterface {
		void method1();
		void method2();
	}
	
	public static class TestObject implements TestInterface{
		public void method1() {
			Assert.fail("Should never be called");
		}
		
		public void method2() {
			Assert.fail("Should never be called");
		}
	}
	
	public static class ExtendsStub extends TestObject implements Stub {
		private boolean method1Called; 
		
		@Mock(id="method1")
		public void method1() {
			method1Called = true;
		}
		
		public boolean wasMethod1Called() {
			return method1Called;
		}
	}

	static interface Stub {
		boolean wasMethod1Called();
	}
	
	public static class NotImplementerStub implements Stub {
		private boolean method1Called; 
		
		@Mock(id="method1")
		public void method1() {
			method1Called = true;
		}	

		public boolean wasMethod1Called() {
			return method1Called;
		}
	}
}
